package com.third.customer.service.data;

import com.third.customer.service.exception.ThirdBadRequestException;
import lombok.Data;
import org.springframework.util.StringUtils;

/**
 * Created by hehuaichun on 2020/5/22.
 */
@Data
public class CustomerReq {

    private Long groupId;

    private Long areaId;

    private String name;

    private String phone;

    private String address;

    private String remark;

    public void validateForCreate() {
        if (groupId == null) {
            throw new ThirdBadRequestException("客户分组信息不能为空!");
        }
        if (areaId == null) {
            throw new ThirdBadRequestException("地区信息不能为空!");
        }

        if (StringUtils.isEmpty(name)) {
            throw new ThirdBadRequestException("客户名不能为空!");
        }
        if (StringUtils.isEmpty(phone)) {
            throw new ThirdBadRequestException("客户联系方式不能为空!");
        }
    }

    public void validateForModify() {
        if (groupId == null && areaId == null &&
                StringUtils.isEmpty(name) &&
                StringUtils.isEmpty(phone) &&
                StringUtils.isEmpty(address) &&
                StringUtils.isEmpty(remark)) {
            throw new ThirdBadRequestException("你没有提交任何修改数据!");
        }
    }
}
